<?PHP
/**
 *  CRONTAB MOTOR
 * 
 *  The script runs all applications' "crontab" method periodically. 
 * 
 */
$projectfolder = '/var/www/clients/socially/';
// include configuration
include $projectfolder . 'config.php';
if (@$_SERVER['QUERY_STRING'] == 'run') {

// scan and include apps classes
    foreach ($data->APPS as $i)
        foreach (glob($projectfolder . 'apps/' . $i . '/lib/*.php') as $j)
            include $j;

// open db connection
    db::connect();

    foreach ($data->APPS as $i)
        if (method_exists($i, 'crontab'))
            $i::crontab();

// close db connection
    db::disconnect();
} else {
// create a new cURL resource
    $ch = curl_init();
// set URL and other appropriate options
    curl_setopt($ch, CURLOPT_URL, 'http://' . DOMAIN . '/crontab.php?run');
    curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and pass it to the browser
    curl_exec($ch);
// close cURL resource, and free up system resources
    curl_close($ch);
}
?>
